package device

import "strconv"

// ErrCode 错误码
type ErrCode int

const (
	// ErrSuccess 成功
	ErrSuccess ErrCode = 0
	// ErrFailure 失败，比如操作数据库失败等
	ErrFailure ErrCode = 1
	// ErrInvalidParam 无效参数
	ErrInvalidParam ErrCode = 2
	// ErrNotImplemented 未实现
	ErrNotImplemented ErrCode = 3
	// ErrDeprecated 已废弃
	ErrDeprecated ErrCode = 4
)

var errCodeName = map[ErrCode]string{
	ErrSuccess:        "SUCCESS",
	ErrFailure:        "FAILURE",
	ErrInvalidParam:   "INVALID_PARAM",
	ErrNotImplemented: "NOT_IMPLEMENTED",
	ErrDeprecated:     "DEPRECATED",
}

func (e ErrCode) String() string {
	s, ok := errCodeName[e]
	if ok {
		return s
	}
	return strconv.Itoa(int(e))
}
